package com.tnxst.phexamination.viewmodel;


import android.app.Application;
import android.content.Context;
import android.content.SharedPreferences;

import androidx.annotation.NonNull;
import androidx.lifecycle.AndroidViewModel;

import com.tnxst.phexamination.constant.Constant;
import com.tnxst.phexamination.dto.DiabetesFollowDTO;
import com.tnxst.phexamination.dto.DoctorDTO;
import com.tnxst.phexamination.room.repository.DiabetesFollowRepository;
import com.tnxst.phexamination.room.repository.DoctorRepository;
import com.tnxst.phexamination.room.repository.HypertensionFollowRepository;
import com.tnxst.phexamination.room.repository.InhabitantRepository;
import com.tnxst.phexamination.room.repository.ServiceDetailsRepository;
import com.tnxst.phexamination.room.repository.ServicePackageRepository;
import com.tnxst.phexamination.room.repository.SignRepository;
import com.tnxst.phexamination.room.repository.TCMHealthRepository;
import com.tnxst.phexamination.room.repository.TbFirstFollowRepository;
import com.tnxst.phexamination.room.repository.TbFollowRepository;
import com.tnxst.phexamination.room.repository.TbPatientRecordRepository;
import com.tnxst.phexamination.room.repository.TbPatientRepository;
import com.tnxst.phexamination.room.repository.TeamDoctorRepository;
import com.tnxst.phexamination.utils.AddressUtils;
import com.tnxst.phexamination.utils.GsonUtils;
import com.tnxst.phexamination.utils.StringUtils;
import com.tnxst.phexamination.vo.UserInfoVo;


public class GlobalViewModel extends AndroidViewModel {

    private static SharedPreferences sharedPreferences;

    private static ServicePackageRepository servicePackageRepository;

    private static ServiceDetailsRepository serviceDetailsRepository;

    private static DoctorDTO userInfo;

    private static SignRepository signRepository;

    private static InhabitantRepository inhabitantRepository;

    private static TeamDoctorRepository teamDoctorRepository;

    private static TbFirstFollowRepository tbFirstFollowRepository;

    private static TbFollowRepository tbFollowRepository;

    private static TbPatientRecordRepository tbPatientRecordRepository;

    private static TbPatientRepository tbPatientRepository;

    private static DiabetesFollowRepository diabetesFollowRepository;

    private static HypertensionFollowRepository hypertensionFollowRepository;

    private static TCMHealthRepository tcmHealthRepository;

    private static DoctorRepository doctorRepository;

    private Context context;

    private String account;

    private AddressUtils addressUtils;

    public GlobalViewModel(@NonNull Application application) {
        super(application);
        context = application;
    }

    public String getAccount(){
        if (StringUtils.isNull(account))
            account = getSharedPreferences().getString(Constant.ACCOUNT,"");
        return account;
    }

    public AddressUtils getAddressUtils(){
        if (addressUtils == null){
            addressUtils = new AddressUtils();
        }
        return addressUtils;
    }

    public DoctorDTO getUserInfo() {
        if (userInfo == null)
            this.userInfo = GsonUtils.fromJson(getSharedPreferences().getString(Constant.LOGIN_RESULT,""),DoctorDTO.class);
        return this.userInfo;
    }

    public void setUserInfo(DoctorDTO userInfo) {
        this.userInfo = userInfo;
    }


    public SharedPreferences getSharedPreferences(){
        if (sharedPreferences == null){
            sharedPreferences = getApplication().getSharedPreferences(Constant.SHAREDPREFERENCES_DATA,Context.MODE_PRIVATE);
        }
        return sharedPreferences;
    }

    public ServicePackageRepository getServicePackageRepository(){
        if (servicePackageRepository == null)
            servicePackageRepository = new ServicePackageRepository(context,getAccount());
        return servicePackageRepository;
    }

    public ServiceDetailsRepository getServiceDetailsRepository(){
        if (serviceDetailsRepository == null)
            serviceDetailsRepository = new ServiceDetailsRepository(context,getAccount());
        return serviceDetailsRepository;
    }

    public SignRepository getSignRepository(){
        if (signRepository == null)
            signRepository = new SignRepository(context,getAccount());
        return signRepository;
    }

    public InhabitantRepository getInhabitantRepository(){
        if (inhabitantRepository == null)
            inhabitantRepository = new InhabitantRepository(context,getAccount());
        return inhabitantRepository;
    }

    public DoctorRepository getDoctorRepository(){
        if (doctorRepository == null)
            doctorRepository = new DoctorRepository(context,getAccount());
        return doctorRepository;
    }

    public TbFirstFollowRepository getTbFirstFollowRepository(){
        if (tbFirstFollowRepository == null)
            tbFirstFollowRepository = new TbFirstFollowRepository(context,getAccount());
        return tbFirstFollowRepository;
    }

    public TeamDoctorRepository getTeamDoctorRepository(){
        if (teamDoctorRepository == null)
            teamDoctorRepository = new TeamDoctorRepository(context,getAccount());
        return teamDoctorRepository;
    }

    public TbFollowRepository getTbFollowRepository(){
        if (tbFollowRepository == null)
            tbFollowRepository = new TbFollowRepository(context,getAccount());
        return tbFollowRepository;
    }

    public TbPatientRecordRepository getTbPatientRecordRepository(){
        if (tbPatientRecordRepository == null)
            tbPatientRecordRepository = new TbPatientRecordRepository(context,getAccount());
        return tbPatientRecordRepository;
    }

    public TbPatientRepository getTbPatientRepository(){
        if (tbPatientRepository == null)
            tbPatientRepository = new TbPatientRepository(context,getAccount());
        return tbPatientRepository;
    }

    public DiabetesFollowRepository getDiabetesFollowRepository(){
        if (diabetesFollowRepository == null)
            diabetesFollowRepository = new DiabetesFollowRepository(context,getAccount());
        return diabetesFollowRepository;
    }

    public HypertensionFollowRepository getHypertensionFollowRepository(){
        if (hypertensionFollowRepository == null)
            hypertensionFollowRepository = new HypertensionFollowRepository(context,getAccount());
        return hypertensionFollowRepository;
    }

    public TCMHealthRepository getTCMHealthRepository(){
        if (tcmHealthRepository == null)
            tcmHealthRepository = new TCMHealthRepository(context,getAccount());
        return tcmHealthRepository;
    }
}
